class YonghusController < ApplicationController
  # GET /yonghus
  # GET /yonghus.xml

  def index
    @yonghus = Yonghu.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @yonghus }
    end
  end
def login
  yonghu=0
  if params[:yonghu]!=nil
    yh=Yonghu.find(:first, :conditions => "username = '#{params[:yonghu][:username]}' AND password = '#{params[:yonghu][:password]}'")
    session[:yonghu]=yh
    if yh!=nil
      redirect_to('/shangpins')
    end
  end
end
  # GET /yonghus/1
  # GET /yonghus/1.xml
  def show
    @yonghu = Yonghu.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @yonghu }
    end
  end

  # GET /yonghus/new
  # GET /yonghus/new.xml
  def new
    @yonghu = Yonghu.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @yonghu }
    end
  end

  # GET /yonghus/1/edit
  def edit
    @yonghu = Yonghu.find(params[:id])
  end

  # POST /yonghus
  # POST /yonghus.xml
  def create
    @yonghu = Yonghu.new(params[:yonghu])

    respond_to do |format|
      if @yonghu.save
        session['yonghu']=@yonghu
        if session['yonghu']==nil
          flash[:notice] = 'Yonghu was successfully created.'
          format.html { redirect_to(@yonghu) }
          format.xml  { render :xml => @yonghu, :status => :created, :location => @yonghu }
        else
            redirect_to('/shangpins/gouwuche')
          end
        else
        format.html { render :action => "new" }
        format.xml  { render :xml => @yonghu.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /yonghus/1
  # PUT /yonghus/1.xml
  def update
    @yonghu = Yonghu.find(params[:id])

    respond_to do |format|
      if @yonghu.update_attributes(params[:yonghu])
        flash[:notice] = 'Yonghu was successfully updated.'
        format.html { redirect_to(@yonghu) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @yonghu.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /yonghus/1
  # DELETE /yonghus/1.xml
  def destroy
    @yonghu = Yonghu.find(params[:id])
    @yonghu.destroy

    respond_to do |format|
      format.html { redirect_to(yonghus_url) }
      format.xml  { head :ok }
    end
  end
end
